package com.grikin.springecharts.controller;


import com.grikin.springecharts.entity.Students;
import com.grikin.springecharts.service.StudentsService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author longyi
 * @since 2023-12-18
 */
@RestController
@RequestMapping("/students")
public class StudentsController {
    @Resource StudentsService studentsService;

    @PostMapping("echart1")
    public Map<String, Object> orderList(@RequestBody Students student) {
        List<Students> list = studentsService.lambdaQuery().eq(Students::getCity,student.getCity())
                .eq(Students::getMajor,student.getMajor())
                .eq(Students::getEnrollmentYear,student.getEnrollmentYear()).list();
        //lambda表达式
        List<Float> grades = new ArrayList<>(); //接收成绩
        List<String> names = new ArrayList<>(); //接收学生姓名
        System.out.println(list);
        //遍历
        for (Students students : list) {
            names.add(students.getName());
            grades.add(students.getScore());
        }
        //hashmap返回
        Map<String, Object> result = new HashMap<>();
        result.put("data",grades);
        result.put("name",names);
        return result;
    }
}
